package com.mushuilingfeng.ddd.user.controller;

import com.mushuilingfeng.ddd.user.bo.UserQueryBO;
import com.mushuilingfeng.ddd.user.service.ITokenService;
import com.mushuilingfeng.ddd.user.service.IUserManagerService;
import com.mushuilingfeng.ddd.user.vo.UserVO;
import com.mushuilingfeng.spring.common.BaseResult;
import com.mushuilingfeng.spring.common.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author 沐水淋风
 * @date 2024/10/20
 */
@RestController
@RequestMapping("/userManager")
@Tag(name = "用户管理")
@AllArgsConstructor
public class UserManagerController {
    private final IUserManagerService userManagerService;
    private final ITokenService tokenService;
    
    @PostMapping("/users")
    public BaseResult<PageResult<UserVO>> users(@RequestBody UserQueryBO bo) {
        return BaseResult.success(userManagerService.users(bo));
    }
    
    @PostMapping("/lockUser/{userId}")
    @Operation(description = "锁定用户")
    public BaseResult<Void> lockUser(@PathVariable("userId") Long userId) {
        userManagerService.lockOrUnlockUser(userId, true);
        return BaseResult.success(null);
    }
    
    @PostMapping("/unlockUser/{userId}")
    @Operation(description = "解锁用户")
    public BaseResult<Void> unlockUser(@PathVariable("userId") Long userId) {
        userManagerService.lockOrUnlockUser(userId, false);
        return BaseResult.success(null);
    }
    
    @PostMapping("/logoutUser/{userId}")
    @Operation(description = "强制用户下线")
    public BaseResult<Void> logoutUser(@PathVariable("userId") Long userId) {
        tokenService.invalidateUserToken(userId);
        return null;
    }
    
}
